package com.iyunsir.man.controller;

import com.iyunsir.common.vo.Result;
import com.iyunsir.man.entity.Man;
import com.iyunsir.man.sever.ManService;
import com.iyunsir.man.vo.ManQuery;
import com.iyunsir.mem.entity.Mem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/man")
public class ManController {
    @Autowired
    private ManService manService;

    @GetMapping("/list")
    @ResponseBody
    public Result<Object> getManList(ManQuery param) {
        List<Man> list = manService.getManList(param);
        Long count = manService.countManList(param);
        return Result.success(list, count);
    }
    @PostMapping("")
    @ResponseBody
    public Result<Object> addMan(Man man){
        manService.addMan(man);
        return Result.success("新增厂商成功");

    }
    @GetMapping("/add/ui")
    public String toAddUI(){

        return "man/manAdd";
    }
    @DeleteMapping("/{ids}")
    @ResponseBody
    public Result<Object> deleteManByIds(@PathVariable("ids") String ids){
        manService.deleteManByIds(ids);
        return Result.success("删除成功！");
    }
    @GetMapping("/{id}")
    public String getManById(@PathVariable("id") Integer id, Model model){
        Man man = manService.getManById(id);
        model.addAttribute("man",man);
        return "man/manEdit";
    }
    @PutMapping("")
    @ResponseBody
    public Result<Object> updateMan(Man man){
        manService.updateMan(man);
        return Result.success("厂家信息修改成功!");

    }
}
